package com.wpml.ware.controller;

import com.wpml.common.util.PageUtils;
import com.wpml.common.util.RUtil;
import com.wpml.common.util.ResultJson;
import com.wpml.ware.entity.WareSkuModel;
import com.wpml.ware.service.WareSkuService;
import com.wpml.ware.vo.SkuHasStockVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 商品库存
 *
 * @author leifengyang
 * @email leifengyang@gmail.com
 * @date 2019-10-08 09:59:40
 */
@RestController
@RequestMapping("ware/waresku")
public class WareSkuController {
    @Autowired
    private WareSkuService wareSkuService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("ware:waresku:list")
    public ResultJson list(@RequestParam Map<String, Object> params){
        PageUtils page = wareSkuService.queryPage(params);

        return ResultJson.ok(page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("ware:waresku:info")
    public ResultJson info(@PathVariable("id") Long id){
        WareSkuModel wareSku = wareSkuService.getById(id);

        return ResultJson.ok(wareSku);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    //@RequiresPermissions("ware:waresku:save")
    public ResultJson save(@RequestBody WareSkuModel wareSku){
		wareSkuService.save(wareSku);

        return ResultJson.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@RequiresPermissions("ware:waresku:update")
    public ResultJson update(@RequestBody WareSkuModel wareSku){
		wareSkuService.updateById(wareSku);

        return ResultJson.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    //@RequiresPermissions("ware:waresku:delete")
    public ResultJson delete(@RequestBody Long[] ids){
		wareSkuService.removeByIds(Arrays.asList(ids));

        return ResultJson.ok();
    }

    @ApiOperation("查询sku是否有库存")
    @PostMapping("/hasStock")
    public RUtil<List<SkuHasStockVo>> hasStock(@RequestBody List<Long> skuIds) {

        List<SkuHasStockVo> list = wareSkuService.checkHasStock(skuIds);

        return new RUtil<List<SkuHasStockVo>>().ok(list);
    }

}
